package com.tudouji.project.d3.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.d3.domain.D3Order;
import com.tudouji.project.d3.service.ID3OrderService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * D3平台订单Controller
 * 
 * @author tudouji
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/d3/order")
public class D3OrderController extends BaseController
{
    @Autowired
    private ID3OrderService d3OrderService;

    /**
     * 查询D3平台订单列表
     */
    @PreAuthorize("@ss.hasPermi('d3:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(D3Order d3Order)
    {
        startPage();
        List<D3Order> list = d3OrderService.selectD3OrderList(d3Order);
        return getDataTable(list);
    }

    /**
     * 导出D3平台订单列表
     */
    @PreAuthorize("@ss.hasPermi('d3:order:export')")
    @Log(title = "D3平台订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(D3Order d3Order)
    {
        List<D3Order> list = d3OrderService.selectD3OrderList(d3Order);
        for (D3Order order : list) {
            String s = order.getReceiverCountry() + "" + order.getReceiverState() + "" + order.getReceiverCity() + "" + order.getReceiverDistrict() + "" + order.getReceiverTown();
            order.setAddress(s);
        }
        ExcelUtil<D3Order> util = new ExcelUtil<D3Order>(D3Order.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取D3平台订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('d3:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(d3OrderService.selectD3OrderById(id));
    }

    /**
     * 新增D3平台订单
     */
    @PreAuthorize("@ss.hasPermi('d3:order:add')")
    @Log(title = "D3平台订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody D3Order d3Order)
    {
        return toAjax(d3OrderService.insertD3Order(d3Order));
    }

    /**
     * 修改D3平台订单
     */
    @PreAuthorize("@ss.hasPermi('d3:order:edit')")
    @Log(title = "D3平台订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody D3Order d3Order)
    {
        return toAjax(d3OrderService.updateD3Order(d3Order));
    }

    /**
     * 删除D3平台订单
     */
    @PreAuthorize("@ss.hasPermi('d3:order:remove')")
    @Log(title = "D3平台订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(d3OrderService.deleteD3OrderByIds(ids));
    }
}
